<template>
	<view class="page">
		<view
			class="flex flex-direction flex-wrap align-stretch justify-center benben-position-layout flex details_flex_0" :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between details_fd0_0'>
				<view class='flex flex-wrap align-center details_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back" data-url="1">
					<text class='fu-iconfont2  wrongQuestion_fd0_0_c0_c0'>&#xE794;</text>
				</view>
				<text class='details_fd0_0_c1'>详情</text>
				<view class='flex align-center justify-end details_fd0_0_c2'>
				</view>
			</view>

		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		<view class="loading_css" v-if="isShow">
			<u-loading size="36" color="#1593FF"></u-loading>
			<view>加载中</view>
		</view>
		<template v-else>
			<view class="detais_info">
				<u-swiper :list="detailsInfo.fengmiantu" height="392" border-radius="0" :autoplay="false"></u-swiper>
				<view class="details_tabs">
					<u-tabs :list="tabsList" :is-scroll="false" font-size="32" inactive-color="#333333"
						active-color="#1593FF" bar-width="40" :current="current" @change="change"></u-tabs>
				</view>
				<template v-if="current == 0">
					<view class="details_name">
						<view class="details_name_1">{{detailsInfo.kechengmingcheng}}</view>
						<view class="details_name_2">{{detailsInfo.jianjie}}</view>
					</view>
					<view style="height: 20rpx;background: #f8f8f8;"></view>
					<view class="details_pause">
						<u-parse :html="detailsInfo.kechengjieshao"></u-parse>
					</view>
				</template>
				<template v-if="current == 1">
					<view class="chapter_list">
						<view class="chapter_item" v-for="(item, index) in chapterList" :key="index" @tap.stop="seeVideo(item)">
							<view class="item_left">{{item.zhangjiemingcheng}}</view>
							<view class="item_right">
								<text v-if="item.shifoukeshikan == 1 && detailsInfo.is_buy == 0">试看</text>
								<image class="item_right_img" v-if="item.shifoukeshikan == 0 && detailsInfo.is_buy == 0" :src='STATIC_URL+"3.png"' mode="aspectFill"></image>
							</view>
						</view>
					</view>
				</template>
				
			</view>
			<view class="details_bottom">
				<view class="bot_1" v-if="detailsInfo.jiage == 0">免费</view>
				<view class="bot_1" v-if="detailsInfo.jiage != 0">{{detailsInfo.jiage}}元</view>
				<view class="bot_2" v-if="detailsInfo.is_buy == 1" @tap.stop="learnNow">立即学习</view>
				<view class="bot_2" v-if="detailsInfo.is_buy == 0 && detailsInfo.jiage == 0" @tap.stop="learnNow">立即学习</view>
				<view class="bot_2" v-if="detailsInfo.is_buy == 0 && detailsInfo.jiage != 0" @tap.stop="generateOrder">立即报名</view>
			</view>
			<view :style="{height: '108rpx'}"></view>
		</template>

	</view>
</template>
<script>
	export default {
		components: {},

		data() {
			return {
				tabsList: [{
					name: '课程介绍'
				}, {
					name: '课程章节'
				}],
				current: 0,
				list: [],
				content: '123456789',
				id: "",  // 资料课程id
				detailsInfo: {
					fengmiantu: []
				},  // 资料详情
				chapterList: [],  // 章节列表
				isClick: false,
				isShow: true,
			};
		},
		computed: {

		},
		watch: {},
		onLoad(options) {
			let {id} = options;
			if (id !== undefined) this.id = id;
			// this.id = 3;
			this.getDetails();
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			getDetails() {
				this.$api.post(global.apiUrls.post65a880ae7fc21, {
					aid: this.id
				}).then(res => {
					// console.log(res);
					this.isShow = false;
					if (res.data.code == 1) {
						this.detailsInfo = res.data.data;
						this.getChapterList();
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			// 获取视频章节列表  post65a884d54a34a
			getChapterList() {
				this.$api.post(global.apiUrls.post65a884d54a34a, {
					aid: this.id
				}).then(res => {
					// console.log(res);
					if (res.data.code == 1) {
						this.chapterList = res.data.data;
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			// 生成待支付订单  post65a8891fc8e94
			generateOrder() {
				
				if (global.userInfo.id == 130) {
					this.$message.info('请登录正式账号进行购买');
					return;
				}
				let _this = this;
				if (_this.isClick) return;
				_this.isClick = true;
				_this.$api.post(global.apiUrls.post65a8891fc8e94, {
					aid: _this.id
				}).then(res => {
					console.log(res);
					if (res.data.code == 1) {
						_this.getPayInfo(res.data.data.dingdanhao);
					} else {
						_this.$message.info(res.data.msg);
						_this.isClick = false;
					}
				})
			},
			// 获取支付信息  post65a9d7d8943ff
			getPayInfo(order_sn) {
				this.$api.post(global.apiUrls.post65a9d7d8943ff, {
					dingdanhao: order_sn,
					type: 2
				}).then(res => {
					if (res.data.code == 1) {
						let data = res.data.data;
						console.log('支付信息', data);
						uni.requestPayment({
							provider: 'wxpay',
							// #ifdef MP-WEIXIN
							timeStamp: data.timeStamp,
							nonceStr: data.nonceStr,
							package: data.package,
							signType: data.signType,
							paySign: data.paySign,
							// #endif
							// #ifdef APP-PLUS
							orderInfo: data,
							// #endif
							success: e => {
								console.log('success', e);
								if (e.errMsg == 'requestPayment:ok') {
									this.$message.info('支付成功');
									setTimeout(() => {
										this.isClick = false;
										this.paySuccessFunc();
									}, 800)
								}
							},
							fail: e => {
								this.isClick = false;
								console.log('fail', e);
								// #ifdef APP-PLUS
								let failMsg = 'requestPayment:fail canceled';
								// #endif
								// #ifndef APP-PLUS
								let failMsg = 'requestPayment:fail cancel';
								// #endif
								if (e.errMsg == failMsg) {
									this.$message.info(this.$t('取消支付'));
								} else {
									this.$message.info(this.$t('支付失败,请稍后重试'));
									// this.$message.info("支付失败,原因为: " + e.errMsg);
								}
							},
							complete: () => {
								
							}
						});
					} else {
						this.$message.info(res.data.msg);
						this.isClick = false;
					}
				})
			},
			paySuccessFunc() {
				uni.navigateTo({
					url: '/pages/index/details/resultPayment'
				})
			},
			
			
			// 查看视频 
			seeVideo(item) {
				if (item.shifoukeshikan == 0) {
					this.$message.info('请购买后查看');
					return;
				} else {
					let time = 0;
					if ((item.shipin.duration - item.yikan) <= 3) {
						time = 0;
					} else {
						time = item.yikan;
					}
					global.videoInfo = {
						aid: item.aid,
						url: item.shipin.path,
						time: time
					}
					uni.navigateTo({
						url: '/pages/benben-built-in/playVideo/playVideo'
					})
				}
			},
			learnNow() {
				this.$message.info('请选择章节观看');
			},
			change(index) {
				this.current = index;
			}
		}
	};
</script>
<style lang="scss" scoped>
	.detais_info {
		.details_tabs {
			margin-top: 16rpx;
		}
		.details_name {
			padding: 16rpx 30rpx 32rpx;
			.details_name_1 {
				font-size: 32rpx;
				font-weight: bold;
			}
			.details_name_2 {
				margin-top: 16rpx;
				font-size: 28rpx;
				color: #999999;
			}
		}
		.details_pause {
			padding: 32rpx;
		}
		
		.chapter_list {
			padding: 20rpx 32rpx;
			.chapter_item {
				background: #F8F8F8;
				border-radius: 8rpx;
				padding: 24rpx;
				margin: 10rpx 0;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.item_left {
					font-size: 28rpx;
					font-weight: 500;
				}
				.item_right {
					font-size: 26rpx;
					color: #1593FF;
				}
				.item_right_img {
					width: 32rpx;
					height: 32rpx;
				}
			}
		}
	}
	.details_bottom {
		width: 100%;
		height: 108rpx;
		background: #FFFFFF;
		box-shadow: 0px -1px 0px 1px #EEEEEE;
		display: flex;
		align-items: center;
		justify-content: space-between;
		position: fixed;
		padding: 0 32rpx;
		bottom: 0;
		.bot_1 {
			color: #FF3A3A;
			font-size: 36rpx;
			font-weight: bold;
		}
		.bot_2 {
			width: 410rpx;
			height: 88rpx;
			background: #1593FF;
			border-radius: 44rpx;
			color: #FFFFFF;
			font-size: 32rpx;
			line-height: 88rpx;
			text-align: center;
		}
	}

	.details_fd2_0 {
		background: rgba(21, 147, 255, 1);
		background-size: 100% !important;
		width: 686rpx;
		height: 88rpx;
		border-radius: 100rpx 100rpx 100rpx 100rpx;
	}

	.details_fd2_0_c0 {
		width: 30rpx;
		height: 50rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.details_fd2_0_c1 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 700;
		color: #FFFFFF;
		margin: 0rpx 0rpx 0rpx 8rpx;
	}

	.details_flex_2 {
		width: 750rpx;
		height: 128rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
	}

	.ben_fu-jyf-parser_1 {
		background-color: #fff;
		padding-left: 32rpx;
		padding-right: 32rpx;
		padding-top: 32rpx;
		padding-bottom: 32rpx;

	}

	.details_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		height: 88rpx;
	}

	.details_fd0_0_c0 {
		width: 40rpx;
		height: 40rpx;
	}

	.details_fd0_0_c0_c0 {
		width: 18rpx;
		height: 32rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.details_fd0_0_c1 {
		font-size: 36rpx;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 50rpx;
	}

	.details_fd0_0_c2 {
		width: 40rpx;
		height: 40rpx;
	}

	.details_flex_0 {
		background: #fff;
		background-size: 100% !important;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background: url(https://app.ezsdcsm.com/images/91.png) no-repeat;
		background-size: 100% 100% !important;
	}

	.page {
		min-height: calc(100vh - var(--window-bottom));
		background: #fff;
		background-size: 100% auto !important;
	}

	.wrongQuestion_fd0_0_c0_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 36rpx;
		width: 40rpx;
	}
</style>